#!/bin/bash
USE_IBUS=0   #use ibus input 
USE_SCIM=0   #use scim input
export INPUT_APP=scim

#===========================================================
# 输入法 （Archlive 输入法预配置）
if [ "x${INPUT_APP}" = "x" ]; then
	export INPUT_APP=fcitx
fi
# 输入法选项 INPUT_APP 优先在 ~/.bash_profile 或者其他先启动的
# 配置文件中中作为全局变量指定
# INPUT_APP 目前可选项：
# fcitx: 小企鹅输入法
# yong: 小小输入法
# ibus: IBUS——新一代输入框架，支持拼音、五笔、二笔等等 
# scim： SCIM--传统输入法
#=======================================
case ${INPUT_APP} in
	fcitx) # 使用小企鹅输入法
		export XIM=fcitx
		export XMODIFIERS="@im=fcitx"
		export XIM_PROGRAM="/usr/bin/fcitx"
		export GTK_IM_MODULE="xim"
		export QT_IM_MODULE="xim"
		export XIM_ARGS="-d"
		[ -z "$(pidof fcitx)" ] && (fcitx &)
		;;
	yong) # 使用小小输入法
		export XIM=yong
		export XMODIFIERS="@im=yong"
		export XIM_PROGRAM="/usr/bin/yong"
		export GTK_IM_MODULE="xim"
		export QT_IM_MODULE="xim"
		export XIM_ARGS="-d"
		[ -z "$(pidof fcitx)" ] && (yong -d &)
		;;
	ibus) # 使用ibus输入框架
		export XMODIFIERS="@im=ibus"
		export GTK_IM_MODULE="ibus"
		export QT_IM_MODULE="ibus"
		export XIM=ibus
		export XIM_PROGRAM=/usr/bin/ibus-daemon
		export XIM_ARGS="-d -x"
		pkill -9 ibus-daemon
		ibus-daemon -d -x 
		#ibus&
		;;
	scim) # 使用scim输入框架
		export XIM=scim
		export XMODIFIERS="@im=scim"
		export XIM_PROGRAM="/usr/bin/scim"
		export GTK_IM_MODULE="scim-bridge"
		export QT_IM_MODULE="scim-bridge"
		export XIM_ARGS="-d"
		[ -z "$(pidof scim)" ] && (scim-bridge &)
		;;
	*) # 暂时没有该输入法的配置文件，请自行添加
		echo "暂时没有该输入法的配置文件，请自行添加"
		;;
	esac
#===========================================================
#
#=======================================
if [ ${USE_SCIM} -eq 1 ] ;then
    export XIM=scim
    export XMODIFIERS="@im=scim"
    export GTK_IM_MODULE=scim
    export QT_IM_MODULE=scim
    export XIM_PROGRAM=/usr/bin/scim
    export XIM_ARGS="-d"

    #export GTK_IM_MODULE="scim"
    #export QT_IM_MODULE="scim"
    export GTK_IM_MODULE="scim-bridge"
    export QT_IM_MODULE="scim-bridge"
fi
#=======================================
if [ ${USE_IBUS} -eq 1 ] ;then
    export XMODIFIERS="@im=ibus"
    export GTK_IM_MODULE="ibus"
    export QT_IM_MODULE="ibus"
    export XIM=ibus
    export XIM_PROGRAM=/usr/bin/ibus-daemon
    export XIM_ARGS="-d -x"

    pkill -9 ibus-daemon
    ibus-daemon -d -x
fi
#=======================================
#export XMODIFIERS="@im=fcitx"
#export XIM=fcitx
#export XIM_PROGRAM=fcitx
#=======================================
# Open office fix
export OOO_FORCE_DESKTOP=gnome 
#export OOO_FORCE_DESKTOP=kde


# . $GLOBALAUTOSTART
# Xmodmap
if [ -e ~/.Xmodmap ] ; then
    echo "xmodmap ~/.Xmodmap"
    xmodmap ~/.Xmodmap
fi

# Xresources
if [ -e ~/.Xresources ] ; then
    echo "xrdb -merge ~/.Xresources"
    xrdb -merge ~/.Xresources
fi 



if [ `pidof urxvtd|wc -w` -eq 0 ] ; then
    exec urxvtd&
else
    killall urxvtd
    exec urxvtd&
fi

if which dbus-launch >/dev/null && test -z "$DBUS_SESSION_BUS_ADDRESS"; then
           eval "$(dbus-launch --sh-syntax --exit-with-session)"
fi

